/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package negocio;
import conexion.Conexion;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
 *
 * @author USUARIO
 */
public class Usuario {
   
    String user;
    String pass;
/*	String nom;
	String ape;
	String rol;
	String email;*/
	
    public Usuario(){
        
    }
public boolean nuevoUsuario(String name, String pass) throws ClassNotFoundException{
    boolean ok= false;
    Conexion conex = new Conexion();
    try
        {
            conex.conectar();
            PreparedStatement pstm = conex.getConnection().prepareStatement("insert into " + "seguridad(usuario,contraseña)" +
            "values (?,?)"); 
            pstm.setString(1,name);
            pstm.setString(2,pass);
	/*		pstm.setString(3,nom);
			pstm.setString(4,ape);
			pstm.setString(5,rol);
			pstm.setString(6,email);*/
			
            pstm.executeUpdate();
            conex.desconectar();
        //    JOptionPane.showMessageDialog(null,"Usuario " + name + " creado correctamente");
            ok = true;
        }
        catch (SQLException e) {
            System.out.println(e);
        }
    return ok;
        }

       public Usuario(String user, String pass) {
        this.user = user;
        this.pass = pass;
		
    }

    public String getPass() {
        return pass;
    }

    public String getUser() {
        return user;
    }
	
/*    public String getNom(){
        return nom;
    }
	
	public String getApe(){
        return ape;
    }
	
	public String getRol() {
        return rol;
    }
	
	public String getEmail(){
        return email;
    }*/
	
        public boolean validarUsuario(String user, String pass)throws ClassNotFoundException {
        //ArrayList lista = new ArrayList();
        boolean ok=false;
        Conexion conex = new Conexion();
        String sql = "Select * from seguridad";
        try{
            conex.conectar();
            PreparedStatement ps = conex.getConnection().prepareStatement(sql);
            ResultSet rs = ps.executeQuery();
           while (rs.next()){
                //lista.add(new Usuario(rs.getString(1), rs.getString(2)));
               if (rs.getString("usuario").trim().equals(user) && rs.getString("Contraseña").trim().equals(pass)){
                ok=true;
            }
           }
            
            conex.desconectar();
           
        }catch(SQLException ex){
            System.out.println(ex);
            
        }        
        return ok;
    }


 }   


